home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / tctnt / keep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  1.4 KB  |  41 lines

  1. /* KEEP.C: Determining the Size of a Program at Runtime
  2.  
  3.         The size of the program can be determined by examining the size
  4.         of the Memory Control Block (MCB) the program resides in.
  5.  
  6.         The 16 bytes immediately preceding the Program Segment Prefix
  7.         (PSP) contain information about the Dos MCB containing your
  8.         program. Unless the user has performed further DOS allocations
  9.         (using allocmem() etc.), the exact size of the program in memory
  10.         can be determined by looking at this information.
  11.  
  12.         The following code shows a structure which defines the information
  13.         in the MCB header and gives a brief description of how to extract
  14.         the size for use with the keep() function.
  15. */
  16.  
  17. #include <dos.h>   // for MK_FP, _psp and keep()
  18.  
  19. // Only 5 pertinent bytes are detailed
  20. typedef struct {
  21.     unsigned char mcb_type;  // 5Ah if last block in chain, else 4Dh
  22.     unsigned owner;          // 0000 if free, 0008 if DOS
  23.     unsigned size;           // size of MCB in paragraphs
  24. } MCB;
  25.  
  26. //*****************************************************************
  27. int main( void )
  28. {
  29.     MCB far *program_psp;
  30.  
  31.     // Install TSR
  32.     // Make a pointer to the controlling MCB and extract the size of
  33.     // the block from it.
  34.  
  35.     // Make pointer to MCB header then terminate & stay resident
  36.     program_psp = (MCB far*) MK_FP(_psp-1, 0);
  37.     keep( 0, program_psp->size );
  38.  
  39.     return 0;
  40. } // endof main()
  41.